package com.stage.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 * Created by Stage on 2017/3/10.
 */
public class DynamicPersonProxy implements InvocationHandler {
    private Object proxied;
    private FileOperation fileWriter = new FileOperation();

    DynamicPersonProxy(Object proxied) {
        this.proxied = proxied;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        method.invoke(this.proxied, args);
        fileWriter.fileWriter("DynamicProxy.txt", "  时间：" + getNowTime() + "方法名：" + method.getName() + "  参数：" + args[0]);
        return null;
    }

    private String getNowTime() {
        java.util.Date date = new java.util.Date();
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = format.format(date);
        return time;
    }
}
